# -*- coding: utf-8 -*-
"""\
cSAXS data preparation script, new flavor.
"""
import sys

first_scan = 508
last_scan = 1728

import ptycho2 as ptycho
import numpy as np

# Need to "hack" the defaults for continuous scans
ptycho.cSAXS.FILENAME_PATTERN = '{read_path}/{prefix}{scan_number:05d}_00000_{index}.{file_extension}'

# Empty parameter structure
p = ptycho.Param()

p.verbose_level = 3
p.interactive = False                         # Not used for now
p.base_path = '/afs/psi.ch/user/b/braun_p/data'
p.user = 'e14438'
#p.scan_number = 300 
p.dpsize = (192,192)                        # Crop size (used to be "asize")
p.ctr = (306,263)                              # Center of cropped array
#p.motors = ('py', 'px')                      # Motor names in y and x
#p.motors_multiplier = 1e-3                    # Multiplier to convert motor values to meters
p.motors = None                               # Motor names in y and x
p.energy = 6.2                                # Energy in keV
p.detector_pixel_size = 172e-6                # Detector pixel size
p.detector_distance = 7.046                    # Detector distance
p.scan_type = 'raster'                            # None (use spec), or 'raster', 'round', 'round_ROI'
p.scan_params.nx = 200
p.scan_params.ny = 0
p.scan_params.step_size_x = .02e-6
p.scan_params.step_size_y = .5e-6

specinfo = ptycho.cSAXS.spec.SpecInfo('/data/CDI/cSAXS_sxdm_2010_02_partial_coherence/spec/dat-files/specES1_started_2010_02_05_1730.dat')

for kk in range(first_scan,last_scan+1):
    p.scan_number = kk
    ptycho.cSAXS.prepare_data(p)
